<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns new DateTimeImmutable instance encapsulating the given DateTime object</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="datetimeimmutable.createfrominterface.html">« DateTimeImmutable::createFromInterface</a></li>
      <li style="float: right;"><a href="datetimeimmutable.getlasterrors.html">DateTimeImmutable::getLastErrors »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.datetimeimmutable.html">DateTimeImmutable</a></li>
    <li>Returns new DateTimeImmutable instance encapsulating the given DateTime object</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="datetimeimmutable.createfrommutable" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeImmutable::createFromMutable</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.6.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTimeImmutable::createFromMutable</span> &mdash; <span class="dc-title">Returns new DateTimeImmutable instance encapsulating the given DateTime object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetimeimmutable.createfrommutable-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>DateTimeImmutable::createFromMutable</strong></span>(<span class="methodparam"><span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span> <code class="parameter">$object</code></span>): <span class="type"><span class="type static">static</span></span></div>

 </div>


 <div class="refsect1 parameters" id="refsect1-datetimeimmutable.createfrommutable-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">object</code></dt>

     <dd>

      <p class="para">
       The mutable <span class="classname"><a href="class.datetime.html" class="classname">DateTime</a></span> object that you want to
       convert to an immutable version. This object is not modified, but
       instead a new <span class="classname"><a href="class.datetimeimmutable.html" class="classname">DateTimeImmutable</a></span> instance is
       created containing the same date time and timezone information.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetimeimmutable.createfrommutable-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a new <span class="classname"><a href="class.datetimeimmutable.html" class="classname">DateTimeImmutable</a></span> instance.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-datetimeimmutable.createfrommutable-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        The method returns an instance of the currently invoked class now. Previously, it created a new instance
        of <span class="classname"><a href="class.datetimeimmutable.html" class="classname">DateTimeImmutable</a></span>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-datetimeimmutable.createfrommutable-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2016">
    <p><strong>示例 #1 Creating an immutable date time object</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$date&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">"2014-06-20&nbsp;11:45&nbsp;Europe/London"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$immutable&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">::</span><span style="color: #0000BB">createFromMutable</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$date&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>